/**
 * Created by lx on 2018/3/29.
 */
//@ sourceURL=planeProjectManage.js 
CommonUtils.regNamespace("com.im.projectInfoManage.planeProjectManage");

$(function() {
    com.im.projectInfoManage.planeProjectManage.invoke.init();
});

com.im.projectInfoManage.planeProjectManage.invoke = function() {
    var client = new com.im.common.ajax();

    /**
     * 页面初始化
     * @private
     */
    function _init() {
        //组件初始化
        _initCommpentAction();
        //表单验证初始化
        _initFormValidate();
        //规划状态
        _queryPlanStateList();
        //规划类型
        _queryPlanTypeList();
        //规划类型变更事件
        $("#planTypeSelect").change(function(){
            _queryPlanList(1);
        });
        //注册规划查询列表事件
        $("#queryPlanListBtn").on("click", function () {
            _queryPlanList(1);
        }).trigger("click");
        //注册工程新增修改保存事件
        $("#addEditProjectBtn").on("click", _addEditProject);
        //注册工程新增事件
        $("#addProjectPlanBtn").on("click", _addProject);
        //条件重置
        $("#vResetCond").on("click", _resetCond);
        //删除
        $('#removeProjectPlanBtn').click(function (){
        	_deleteProject();
        });
        //导出
        $('#exportProjectPlanBtn').click(function (){
        	_exportList();
        });
        $('#printProjectPlanBtn').click(function (){
        	  CreateFormPage("规划工程", $('#planTable'))
        });
        $(".money-control").blur(function () {
            _moneyInit(this,'blur')
        });
        $(".money-control").focus(function () {
            _moneyInit(this,'focus')
        });
    };

    function _initCommpentAction() {
        //时间插件
        $('#startDatepicker,#endDatepicker').datepicker({
        	startView: 'decade',  
            minView: 'decade',  
            format: 'yyyy',  
            maxViewMode: 2,  
            minViewMode:2,  
            autoclose: true 
        });

        //复选框
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass   : 'iradio_minimal-blue'
        });

        //下拉框
        $('.select2').select2();

        //建设单位查询组件
        $("#developOrgSelect").unitselCommpent({
            elmIdSel : "developOrgSelect",//需要展示的位置下拉框
            unitType : "10",//单位类型 为空的时候全部查询
            callbackFunc: function (objvalue, objname) {//下拉框值改变时回调
            	_queryPlanList(1);
            }
        });

        //建设单位查询组件2
        $("#developOrgInput2").unitselCommpent({
            elmIdSel : "developOrgInput2",//需要展示的位置下拉框
            unitType : "10",//单位类型 为空的时候全部查询
            defaultContent : false,
            callbackFunc: function (objvalue, objname) {//下拉框值改变时回调
            	$('#addEditProjectForm').data('bootstrapValidator').updateStatus('developOrgInput2', 'NOT_VALIDATED',null).validateField('developOrgInput2');
            }
        });

        //工程联系人查询组件
        $("body").append($($.parseHTML("<div class='modal fade bs-example-modal-lg' id='modal2' ></div>")));
        $("body").append($($.parseHTML("<div class='modal fade bs-example-modal-lg' id='modal3' ></div>")));
        $("#queryProjectUserBtn").click(function() {
            $("#projectUserInput").userSearchCommpent({
                elmIdOut : "projectUserInput",
                elmIdModal : "modal2",
                elmIdOrgModal : "modal3",
                callbackFunc: function (staffId, staffName, mobilePhone) {
                    $("#projectUserInput").attr("vaLxrId", staffId);
                    $("#projectUserNumberInput").val(mobilePhone);
                    $('#addEditProjectForm').data('bootstrapValidator').updateStatus('projectUserInput', 'NOT_VALIDATED',null).validateField('projectUserInput');
                    $('#addEditProjectForm').data('bootstrapValidator').updateStatus('projectUserNumberInput', 'NOT_VALIDATED',null).validateField('projectUserNumberInput');
                }
            });
        });

        //工程负责人查询组件
        $("body").append($($.parseHTML("<div class='modal fade bs-example-modal-lg' id='modal4' ></div>")));
        $("body").append($($.parseHTML("<div class='modal fade bs-example-modal-lg' id='modal5' ></div>")));
        $("#queryProjectUserBtn2").click(function() {
            $("#projectUserInput2").userSearchCommpent({
                elmIdOut : "projectUserInput2",
                elmIdModal : "modal4",
                elmIdOrgModal : "modal5",
                callbackFunc: function (staffId, staffName) {
                    $("#projectUserInput2").attr("vaFzrId", staffId);
                    $('#addEditProjectForm').data('bootstrapValidator').updateStatus('projectUserInput2', 'NOT_VALIDATED',null).validateField('projectUserInput2');
                }
            });
        });
    }

    /**
     * 表单验证
     * @param $form
     * @returns {boolean}
     * @private
     */
    function _formValidate($form) {
        $form.data("bootstrapValidator").validate();
        return $form.data("bootstrapValidator").isValid();
    }

    /**
     * 表单验证初始化
     * @private
     */
    function _initFormValidate(flag) {
        $("#addEditProjectForm").bootstrapValidator({
            live: 'enabled',
            excluded: [':hidden'],
            feedbackIcons: {valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-loadData'},
            fields: {
                addEditProjectName: {validators: {notEmpty: {message: "请填写工程名称"}}},
                planTypeSelect2: {validators: {notEmpty: {message: "请选择所属规划"}}},
                developOrgInput2: {validators: {notEmpty: {message: "请选择建设单位"}}},
                planStateSelect: {validators: {notEmpty: {message: "请选择状态"}}},
                startDatepicker: {trigger:"change",validators: {notEmpty: {message: "请选择开工年"}}},
                endDatepicker: {trigger:"change",validators: {
                    notEmpty: {message: "请选择完工年"},
                    callback: {message: "完工年不能小于开工年", callback:function(value, validator,$field){
                        if($("#startDatepicker").val() == null || $("#startDatepicker").val() == "" ||  $("#endDatepicker").val() == null||  $("#endDatepicker").val() == ""){
                            return true;
                        }
                        return new Date($("#startDatepicker").val()) <= new Date($("#endDatepicker").val());
                    }}
                }},
                projectUserInput: {validators: {notEmpty: {message: "请选择工程联系人"}}},
                projectUserNumberInput: {validators: {notEmpty: {message: "联系人电话不存在"}}},
                projectUserInput2: {validators: {notEmpty: {message: "请选择工程负责人"}}},
                addEditProjectBbz: {validators: {notEmpty: {message: "请填写部补助金额"}, numeric: {message: '部补助只能输入数字'},callback : {message: "小数点后精度不能多于2位", callback:function(value, validator,$field){
                    var tstr = value.split('.');
                    if(tstr.length > 1 && tstr[1].length > 2){
                        return false;
                    }
                    return true;
                }}}},
                addEditProjectScz: {validators: {notEmpty: {message: "请填写省财政金额"}, numeric: {message: '省财政只能输入数字'},callback : {message: "小数点后精度不能多于2位", callback:function(value, validator,$field){
                    var tstr = value.split('.');
                    if(tstr.length > 1 && tstr[1].length > 2){
                        return false;
                    }
                    return true;
                }}}},
                addEditProjectGsslrz: {validators: {notEmpty: {message: "请填写政府融资金额"}, numeric: {message: '政府融资只能输入数字'},callback : {message: "小数点后精度不能多于2位", callback:function(value, validator,$field){
                    var tstr = value.split('.');
                    if(tstr.length > 1 && tstr[1].length > 2){
                        return false;
                    }
                    return true;
                }}}},
                addEditProjectQyzc: {validators: {notEmpty: {message: "请填写部企业自筹金额"}, numeric: {message: '企业自筹只能输入数字'},callback : {message: "小数点后精度不能多于2位", callback:function(value, validator,$field){
                    var tstr = value.split('.');
                    if(tstr.length > 1 && tstr[1].length > 2){
                        return false;
                    }
                    return true;
                }}}},
                addEditProjectSzpt: {validators: {notEmpty: {message: "请填写市州配套金额"}, numeric: {message: '市州配套只能输入数字'},callback : {message: "小数点后精度不能多于2位", callback:function(value, validator,$field){
                    var tstr = value.split('.');
                    if(tstr.length > 1 && tstr[1].length > 2){
                        return false;
                    }
                    return true;
                }}}},
                addEditProjectJj: {validators: {notEmpty: {message: "请填写部规划工程简介"}}}
            }
        });

        if(flag == undefined) {
            $('#addEditModal').on('hidden.bs.modal', function () {
                $('#addEditProjectForm').data('bootstrapValidator').destroy();
                $('#addEditProjectForm').data('bootstrapValidator', null);
                _initFormValidate("again");
            });
        }
    }

    /**
     * 获取规划类型列表
     * @private
     */
    function _queryPlanTypeList() {
        var param = {};
        var result = client.callAsJson("projectInfoService/queryPlanProjClassConstList", param);
        if (!result.success) {
            toastr.error(result.resultMsg);
            return;
        }

        //规划类型列表添加元素
        var planTypeSelect = $("#planTypeSelect");
        var planTypeSelect2 = $("#planTypeSelect2");
        planTypeSelect.append("<option selected='selected'>全部</option>");
        $.each(result.result, function (i, item) {
            if(i == 0) {
                planTypeSelect.append("<option vaPlanTypeId='" + item.paramValValue + "'>" + item.paramValName + "</option>");
                planTypeSelect2.append("<option vaPlanTypeId='" + item.paramValValue + "' selected='selected'>" + item.paramValName + "</option>");
            } else {
                planTypeSelect.append("<option vaPlanTypeId='" + item.paramValValue + "'>" + item.paramValName + "</option>");
                planTypeSelect2.append("<option vaPlanTypeId='" + item.paramValValue + "'>" + item.paramValName + "</option>");
            }
        });
    }

    /**
     * 获取规划状态列表
     * @private
     */
    function _queryPlanStateList() {
        var param = {};
        var planStateList = null;
        param.tabName = "T_PLAN_PROJECT";
        param.colName ="STATUS_CD";
        var result = client.callAsJson("commonService/queryTabColParam", param);
        if (result.success) {
            planStateList = result.result;
        } else {
            toastr.error(result.resultMsg);
            return;
        }

        //规划状态列表添加元素
        var planStateSelect = $("#planStateSelect");
        $.each(planStateList, function (i, item) {
            if(i == 0) {
                planStateSelect.append("<option vaPlanStateId='" + item.colVal + "' selected='selected'>" + item.colValName + "</option>");
            } else {
                planStateSelect.append("<option vaPlanStateId='" + item.colVal + "'>" + item.colValName + "</option>");
            }
        });
    }

    /**
     * 获取规划列表
     * @param index 页索引
     * @private
     */
    function _queryPlanList(index) {
        if(com.im.projectInfoManage.planeProjectManage.planColumns == undefined) {
            com.im.projectInfoManage.planeProjectManage.planColumns = [
                [{field:'全选',title:"全选",width:30,checkbox:true,rowspan:2,fitColumns:true},
                    {field:'序号',title:"序号",width:30,rowspan:2,fitColumns:true,formatter: function(value,row,index){
                    	if(row.planProjId){
                    		return index + 1;
                    	}
                    }},
                    {field:'planProjName',title:"工程名称",width:140,rowspan:2,fitColumns:true,halign:'center',align:'left'},
                    {field:'planProjClassName',title:"所属规划",width:100,rowspan:2,fitColumns:true},
                    {field:'developOrgName',title:"建设单位",width:100,rowspan:2,fitColumns:true},
                    {title:"建设年限",width:200,colspan:2,fitColumns:true},
                    {field:'leadingPersonName',title:"工程<br/>负责人",width:50,rowspan:2,fitColumns:true},
                    {field:'linkmanName',title:"工程<br/>联系人",width:50,rowspan:2,fitColumns:true},
                    {field:'description',title:"主要建设内容",width:200,rowspan:2,fitColumns:true,align:'left',formatter: function(value,row,index){
                    	if(value){
                    	    if(value == "合计:") {
                                return value;
                            }else if(value.length > 40){
	                            return "<a href='javascript:;' data-toggle='modal' onclick='com.im.projectInfoManage.planeProjectManage.invoke.showProjectContent("+ index +");'>" + value.substr(0,40) + "...</a>";
	                        }else{
	                            return "<a href='javascript:;' data-toggle='modal' onclick='com.im.projectInfoManage.planeProjectManage.invoke.showProjectContent("+ index +");'>" + value + "</a>";
	                        }
                    	}
                    }},
                    {title:"阶段资金构成（单位：万元）",width:400,colspan:6,fitColumns:true},
                    {field:'statusName',title:"状态",width:50,rowspan:2,fitColumns:true},
                    {field:'vaOperation',title:"操作",width:50,rowspan:2,fitColumns:true,formatter: function(value,row,index){
                    	if(row.planProjId){
                    		return  "<a href='javascript:;' onclick='com.im.projectInfoManage.planeProjectManage.invoke.editProject("+ index +");' title='修改'><i class='fa fa-edit'></i></a>";
                    	}
                    }}],
                [{field:'startDt',title:"开工年",fitColumns:true},
                    {field:'endDt',title:"完工年",fitColumns:true},
                    {field:'total',title:"合计",fitColumns:true},
                    {field:'fundSourceBu',title:"部补助",fitColumns:true},
                    {field:'fundSourceSheng',title:"省财政",fitColumns:true},
                    {field:'fundSourceGao',title:"政府融资",fitColumns:true},
                    {field:'fundSourceShi',title:"市州配套",fitColumns:true},
                    {field:'fundSourceQi',title:"企业自筹",fitColumns:true}]
            ];
        }

        var req = {};
        req.pageInfo = {};
        req.pageInfo.pageNumber = index;
        req.pageInfo.pageSize = 20;
        req.planProjClass = $("#planTypeSelect option:selected").attr("vaPlanTypeId");
        var developOrg = $("#developOrgSelect option:selected").attr("value");
        if(developOrg != ''){
        	req.developOrg = developOrg;
        }else{
        	delete req.developOrg;
        }
        req.planProjName = $("#projectNameInput").val();

        var resp = client.callAsJson("projectInfoService/queryPlanProjList", req);
        if (!resp.success) {
            toastr.error(resp.resultMsg);
            return;
        } else {

        }

        $("#planTable").empty();
        $("#planTable").datagrid({
            checkOnSelect:true,
        	pagination:true,
            nowrap:false,
            fitColumns:true,
        	showFooter: true,
        	columns:com.im.projectInfoManage.planeProjectManage.planColumns,
        	data:resp.result
        });
        var p = $('#planTable').datagrid('getPager');
        $(p).pagination({
            total : resp.result.total,
            pageSize : resp.result.pageSize,
            pageNumber : resp.result.pageNumber,
            pageList : [20 , 40],
            beforePageText: '第',
            afterPageText: '页    共 {pages}  页',
            displayMsg: '当前显示 {from} - {to} 条记录 共 {total}  条记录',
            onSelectPage:function(pageNumber, pageSize){
                _queryPlanList(pageNumber, false);
            }
        });
    }

    /**
     * 新增修改工程
     * @private
     */
    function _addEditProject() {
        if(!_formValidate($("#addEditProjectForm"))) {
            return;
        }

        var req = {};
        //有值为修改工程
        req.planProjId = $("#addEditProjectId").val();
        req.planProjName = $("#addEditProjectName").val();
        req.planProjClass = $("#planTypeSelect2 option:selected").attr("vaPlanTypeId");
        //req.developOrg = $("#developOrgInput2").attr("vaDevelopOrgId");
        req.developOrg = $("#developOrgInput2 option:selected").attr("value");
        req.statusCd = $("#planStateSelect option:selected").attr("vaPlanStateId");
        req.startDt = _dateFormat($("#startDatepicker").val());
        req.endDt = _dateFormat($("#endDatepicker").val());
        req.linkman = $("#projectUserInput").attr("vaLxrId");
        req.linkmanTel = $("#projectUserNumberInput").val();
        req.leadingPerson = $("#projectUserInput2").attr("vaFzrId");
        req.fundSourceBu = $("#addEditProjectBbz").val();
        req.fundSourceSheng = $("#addEditProjectScz").val();
        req.fundSourceGao = $("#addEditProjectGsslrz").val();
        req.fundSourceQi = $("#addEditProjectQyzc").val();
        req.fundSourceShi = $("#addEditProjectSzpt").val();
        req.description = com.im.common.util.escapeTextArea($("#addEditProjectJj").val());
        req.introduce = com.im.common.util.escapeTextArea($("#addEditProjectJj").val());

        var url = null;
        var resultMsg = null;
        if(req.planProjId == null || req.planProjId == "") {
            url = "projectInfoService/addPlanProj";
            resultMsg = "新增工程规划成功";
        } else {
            url = "projectInfoService/updatePlanProj";
            resultMsg = "修改工程规划成功";
        }

        var resp = client.callAsJson(url, req);
        if (!resp.success) {
            toastr.error(resp.resultMsg);
            return;
        }
        toastr.success(resultMsg);
        _queryPlanList(1, true);
        $("#addEditModal").modal("hide");
    }

    /**
     * 新增工程
     * @private
     */
    function _addProject() {
    	$('#addEditModal .modal-title').html('工程新增');
        $("#addEditProjectId").val("");
        $("#addEditProjectName").val("");
        $("#planTypeSelect2").find("option:selected").removeAttr("selected");
        $("#planTypeSelect2").find("option").first().attr("selected", "selected");
        $("#planTypeSelect2").trigger("change");
        $("#developOrgInput2").find("option:selected").removeAttr("selected");
        $("#developOrgInput2").find("option").first().attr("selected", "selected");
        $("#developOrgInput2").trigger("change");
        $("#planStateSelect").find("option:selected").removeAttr("selected");
        $("#planStateSelect").find("option").first().attr("selected", "selected");
        $("#planStateSelect").trigger("change");
        $("#startDatepicker").val("");
        $("#endDatepicker").val("");
        $("#projectUserInput").val("");
        $("#projectUserInput").attr("vaLxrId", "");
        $("#projectUserNumberInput").val("");
        $("#projectUserInput2").val("");
        $("#projectUserInput2").attr("vaFzrId", "");
        $("#addEditProjectBbz").val("0.00");
        $("#addEditProjectScz").val("0.00");
        $("#addEditProjectGsslrz").val("0.00");
        $("#addEditProjectQyzc").val("0.00");
        $("#addEditProjectSzpt").val("0.00");
        $("#addEditProjectJj").val("");
        $("#addEditModal").modal("show");
    }

    /**
     *  修改工程
     * @private
     */
    function _editProject(index) {
    	$('#addEditModal .modal-title').html('工程修改');
        var row = $('#planTable').datagrid('getData').rows[index];

        $("#addEditProjectId").val(row.planProjId);
        $("#addEditProjectName").val(row.planProjName);
        $("#planTypeSelect2").val(row.planProjClassName).trigger("change");
        $("#developOrgInput2").val(row.developOrg).trigger("change");
        $("#planStateSelect").val(row.statusName).trigger("change");
        $("#startDatepicker").val(row.startDt);
        $("#endDatepicker").val(row.endDt);
        $("#projectUserInput").val(row.linkmanName);
        $("#projectUserInput").attr("vaLxrId", row.linkman);
        $("#projectUserNumberInput").val(row.linkmanTel);
        $("#projectUserInput2").val(row.leadingPersonName);
        $("#projectUserInput2").attr("vaFzrId", row.leadingPerson);
        $("#addEditProjectBbz").val(row.fundSourceBu);
        $("#addEditProjectScz").val(row.fundSourceSheng);
        $("#addEditProjectGsslrz").val(row.fundSourceGao);
        $("#addEditProjectQyzc").val(row.fundSourceQi);
        $("#addEditProjectSzpt").val(row.fundSourceShi);
        $("#addEditProjectJj").val(com.im.common.util.descapeTextArea(row.description));
        $("#addEditModal").modal("show");
    }

    /**
     *  删除工程
     * @private
     */
    function _deleteProject() {
        var planProjIds = new Array();
        var uncheckMsg = "";
        $.each($('#planTable').datagrid('getChecked'), function(index, item){
        	if(item.statusCd != 10){
        		if(uncheckMsg == ''){
        			uncheckMsg += (index+1);
        		}else{
            		uncheckMsg += ',' + (index+1);
        		}
        	}else{
                planProjIds.push(item.planProjId);
        	}
        });
        if(uncheckMsg != ''){
        	toastr.info("第"+ uncheckMsg + '行数据不能删除，请重新选择');
        	return;
        }else if(uncheckMsg == '' && planProjIds.length == 0){
        	toastr.info('请选中至少一行记录再删除');
        	return;
        }
        com.im.common.confirm("是否删除工程", null, function () {
            var req= {};
            req.planProjIds = planProjIds.join(',');
            var resp = client.callAsJson("projectInfoService/deletePlanProj", req);
            if (!resp.success) {
                toastr.error(resp.resultMsg);
                return;
            }
            toastr.success("删除工程规划成功");
            _queryPlanList(1, true);
        });
    }

    /**
     * 工程简介
     * @param object
     * @private
     */
    function _showProjectContent(index) {
        var row = $('#planTable').datagrid('getData').rows[index];
        var req= {};
        req.planProjId = (row.planProjId);
        var resp = client.callAsJson("projectInfoService/queryPlanProjDetail", req);
        if (!resp.success) {
            toastr.error(resp.resultMsg);
            return;
        }

        $("#vProjectName").text(row.planProjName+"----建设内容");
        $("#vProjectContent").html(resp.result.description);
        $("#projectContentModal").modal("show");
    }

    /**
     * 条件重置
     * @private
     */
    function _resetCond() {
        $("#developOrgInput").val("").trigger("change");
        $("#planTypeSelect").find("option:selected").removeAttr("selected");
        $("#planTypeSelect").find("option").first().attr("selected", "selected");
        $("#planTypeSelect").trigger("change");
        $("#projectNameInput").val("");
        _queryPlanList(1);//重复调用
    }
    
    function _dateFormat(date) {
        var date = new Date(date);
        return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
    }
    //导出表格
    function _exportList(){
    	var param = {
    		    "classes": "ProjectInfoService",
    		    "fileName": "规划工程列表",
    		    "method": "queryPlanProjList",
    		    "title": {
    		        "planProjName":"工程名称",
    		        "planProjClassName": "所属规划",
    		        "developOrgName": "建设单位",
    		        "startDt": "开工年$建设年限",
    		        "endDt": "完工年$建设年限",
    		        "leadingPersonName": "工程负责人",
    		        "linkmanName": "工程联系人",
    		        "description": "主要建设内容",
    		        "total": "合计$阶段资金构成（单位：万元）",
    		        "fundSourceBu": "部补助$阶段资金构成（单位：万元）",
    		        "fundSourceSheng": "省财政$阶段资金构成（单位：万元）",
    		        "fundSourceGao": "政府融资$阶段资金构成（单位：万元）",
    		        "fundSourceShi": "市州配套$阶段资金构成（单位：万元）",
    		        "fundSourceQi": "企业自筹$阶段资金构成（单位：万元）",
    		        "statusName": "状态"
    		    }
    		};
    	param.param={};
    	param.param.planProjClass = $("#planTypeSelect option:selected").attr("vaPlanTypeId");
        var developOrg = $("#developOrgSelect option:selected").attr("value");
        if(developOrg != ''){
        	param.param.developOrg = developOrg;
        }else{
        	delete param.param.developOrg;
        }
        param.param.planProjName = $("#projectNameInput").val();
    	var url='/InfoManageWeb/commonService/export?json='+encodeURI(JSON.stringify(param));
    	window.open(url, '_blank');
    }

    function CreateFormPage(strPrintName, printDatagrid) {
   	 var tableString = '<table cellspacing="0" class="pb" style="TABLE-LAYOUT: fixed">';
   	 var frozenColumns = printDatagrid.datagrid("options").frozenColumns;  // 得到frozenColumns对象
   	 var columns = printDatagrid.datagrid("options").columns;    // 得到columns对象
   	 var nameList = '';
   	
   	 // 载入title
   	 if (typeof columns != 'undefined' && columns != '') {
   	     $(columns).each(function (index) {
   	         tableString += '\n<tr>';
   	         if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {
   	             for (var i = 1-index; i < frozenColumns[index].length-1+index; ++i) {
   	                 if (!frozenColumns[index][i].hidden) {
   	                     tableString += '\n<th width="' + frozenColumns[index][i].width + '"';
   	                     if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) {
   	                         tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"';
   	                     }
   	                     if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) {
   	                         tableString += ' colspan="' + frozenColumns[index][i].colspan + '"';
   	                     }
   	                     if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '') {
   	                         nameList += ',{"f":"' + frozenColumns[index][i].field + '", "a":"' + frozenColumns[index][i].align + '"}';
   	                     }
   	                     tableString += '>' + frozenColumns[0][i].title + '</th>';
   	                 }
   	             }
   	         }
   	         for (var i =1-index; i < columns[index].length-1+index; ++i) {
   	             if (!columns[index][i].hidden) {
   	                 tableString += '\n<th width="' + columns[index][i].width + '"';
   	                 if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) {
   	                     tableString += ' rowspan="' + columns[index][i].rowspan + '"';
   	                 }
   	                 if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) {
   	                     tableString += ' colspan="' + columns[index][i].colspan + '"';
   	                 }
   	                 if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '') {
   	                     nameList += ',{"f":"' + columns[index][i].field + '", "a":"' + columns[index][i].align + '"}';
   	                 }
   	                 tableString += '>' + columns[index][i].title + '</th>';
   	             }
   	         }
   	         tableString += '\n</tr>';
   	     });
   	 }
   	 // 载入内容
   	 var rows = printDatagrid.datagrid("getRows"); // 这段代码是获取当前页的所有行
   	 var nl = eval('([' + nameList.substring(1) + '])');
 	 nl.splice(16,0,nl[7]);
 	 nl.splice(7,1);
 	 nl.splice(4,0,nl[7]);
	 nl.splice(5,0,nl[8]);
	 nl.splice(9,2);
 	   
   	 for (var i = 0; i < rows.length; ++i) {
   	     tableString += '\n<tr>';
   	     $(nl).each(function (j) {
   	         var e = nl[j].f.lastIndexOf('_0');
   	
   	         tableString += '\n<td';
   	         if (nl[j].a != 'undefined' && nl[j].a != '') {
   	             tableString += ' style="text-align:' + nl[j].a + ';style="WORD-WRAP: break-word" width="20"';
   	         }else{
   	        	 tableString += ' "TABLE-LAYOUT:fixed;WORD-BREAK:break-all" width="20"';
   	         }
   	         tableString += '>';
   	         if (e + 2 == nl[j].f.length) {
   	             tableString += rows[i][nl[j].f.substring(0, e)];
   	         }
   	         else{
   	        	if(typeof(rows[i][nl[j].f])!='undefined'&&rows[i][nl[j].f]!=null){
  	        		 tableString += rows[i][nl[j].f];
  	        	 }
  	        	 if(j==0){
  	        		tableString +=(i+1);
  	        	 }
   	             }
   	         
   	         tableString += '</td>';
   	     });
   	     tableString += '\n</tr>';
   	 }
   	 tableString += '\n</table>';
   	  $("#printdata").val(tableString);
   	 var popupwin =window.open("print", '_blank');
   }

    //资金输入框聚焦和失去焦点事件，tag对象，type类型
    function _moneyInit(tag,type){

        if(type == 'focus'){
            //聚焦
            var tmpval = $(tag).val();

            if(tmpval == undefined || tmpval == '0' || tmpval == '0.00'){
                $(tag).val('');
            }

        }else{
            //失去焦点
            var tmpval = $(tag).val();

            if(tmpval == undefined || tmpval == ''){
                $(tag).val('0.00');
            }
        }

    }
    
    return {
        init : _init,
        editProject : _editProject,
        deleteProject : _deleteProject,
        showProjectContent : _showProjectContent
    }
}();